//
//  APPRadio_TextViewAlertViewController.swift
//  APP
//
//  Created by Rdxer on 2017/12/20.
//  Copyright © 2017年 Rdxer. All rights reserved.
//

import UIKit

/// 单选 + 文本输入
class APPRadio_TextViewAlertViewController: APPTextViewAlertViewController {

    open var radioSelectDidChangCallBack:((_ alert:APPAlertViewController)->())?
    
    open lazy var Y_Button = UIButton.init().then {
        $0.setTitle("同意", for: .normal)
        $0.setTitleColor(style.textColor, for: .normal)
        $0.setImage(( #imageLiteral(resourceName: "check_unchecked")), for: .normal)
        $0.setImage(( #imageLiteral(resourceName: "check_checked")), for: .selected)
        $0.isSelected = true
    }
    
    
    open lazy var N_Button = UIButton.init().then {
        $0.setTitle("不同意", for: .normal)
        $0.setTitleColor(style.textColor, for: .normal)
        $0.setImage(( #imageLiteral(resourceName: "check_unchecked")), for: .normal)
        $0.setImage(( #imageLiteral(resourceName: "check_checked")), for: .selected)
    }

    var topCustomWarpView = UIView.init()
    
    @objc func N_ButtonClick(_ sender: UIButton) {
        N_Button.isSelected = true
        Y_Button.isSelected = false
        radioSelectDidChangCallBack?(self)
    }
    
    @objc func Y_ButtonClick(_ sender: UIButton) {
        N_Button.isSelected = false
        Y_Button.isSelected = true
        radioSelectDidChangCallBack?(self)
    }
    
    
    open override func prepareSubViews(){
        prepareAddListenKeyboard()
        
        view.addSubviews([
            backView,
            containerView.addSubviews([
                title_Label,
                topCustomWarpView.addSubviews([
                    Y_Button,
                    N_Button
                    ]),
                textView,
                buttonsContainerView.addSubviews([
                    cancelButton,
                    confirmButton
                    ])
                ])
            ])
        
        
        Y_Button.addTarget(self, action: #selector(Y_ButtonClick(_:)), for: .touchUpInside)
        N_Button.addTarget(self, action: #selector(N_ButtonClick(_:)), for: .touchUpInside)
    }
    
    open override func layoutSubViews(){
        
        backView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        containerView.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalTo(w)
        }
        
        title_Label.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(titleHeight)
        }
        
        buttonsContainerView.snp.makeConstraints { (make) in
            make.bottom.left.right.equalToSuperview()
            make.height.equalTo(rowHeight)
        }
        
        topCustomWarpView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(title_Label.snp.bottom).offset(margin)
            make.height.equalTo(rowHeight)
        }
        
        textView.snp.makeConstraints { (make) in
            make.top.equalTo(topCustomWarpView.snp.bottom).offset(margin)
            make.bottom.equalTo(buttonsContainerView.snp.top).offset(-margin)
            make.left.equalToSuperview().offset(margin)
            make.right.equalToSuperview().offset(-margin)
            make.height.equalTo(textViewH)
        }
        
        buttonsContainerView.xx_HorizontalTile(withSubviews: [cancelButton,confirmButton], insets: .zero)
        topCustomWarpView.xx_HorizontalTile(withSubviews: [Y_Button,N_Button], insets: .zero)
    }
}
